import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:ichinesereader/controller/assessments.dart';
import 'package:ichinesereader/pages/teacher/assessmentStepper.dart';
import 'package:ichinesereader/widgets/dialogs/simpleAlertDialog.dart';
import '../../controller/user.dart';
import '../../themes/appTheme.dart';
import '../dialogs/switchClassDialog.dart';

class FloatingActionButtonCreateAssessment extends StatelessWidget {
  FloatingActionButtonCreateAssessment({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final AssessmentsController _controller = Get.find();
    UserController _userController = Get.find();
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        FloatingActionButton(
          backgroundColor: Get.isDarkMode
              ? Theme.of(context).primaryColorDark
              : AppTheme.colors.pinkBtn,
          foregroundColor: Get.isDarkMode
              ? Colors.black
              : Theme.of(context).primaryColorLight,
          heroTag: Text('createassessment0000'.tr),
          tooltip: 'Create Assessment'.tr,
          onPressed: () {
            //List<String> bookids = [];
            if (_controller.selectedAssessmentBenchmarkTests.length > 0) {
              // var type = Constants.assessmentTypes
              //     .where((element) =>
              //         element.assessmentType ==
              //         _assessmentBookType.assessmentType)
              //     .first
              //     .displayName;

              Get.to(() => AssessmentSteps(
                    isNew: true,
                    books: _controller.selectedAssessmentBenchmarkTests,
                  ));

              // _controller.selectedAssessmentBooks.forEach(
              //   (element) {
              //     if (!bookids.contains(element.bookId))
              //       bookids.add(element.bookId.toString());
              //   },
              // );
              // var book = _controller.selectedAssessmentBooks[0];
              // var type = Constants.assessmentTypes
              //     .where((element) =>
              //         element.assessmentType ==
              //         _assessmentBookType.assessmentType)
              //     .first
              //     .displayName;
              // AssessedBooks books = new AssessedBooks();
              // books.assessedBooks = [];
              // books.assessedBooks?.add(AssessedBook(
              //     id: book.bookId, title: book.bookTitle, type: type));

              // if (GetPlatform.isWeb || GetPlatform.isDesktop) {
              // } else {
              //   Get.to(() => InAppWebViewTeacherCreateAssessmentScreen(
              //         isNew: true,
              //         assessedBooks: books,
              //       ));
              // }
            } else {
              showGeneralDialog(
                  context: context,
                  transitionDuration: Duration(milliseconds: 400),
                  pageBuilder: (bc, ania, anis) {
                    return SimpleAlertDialog(
                        title: 'No Book'.tr,
                        message:
                            'Please select at least one book to ASSIGN!'.tr);
                  });
            }
          },
          child: Obx(() {
            int? num;
            if (_controller.selectedAssessmentBenchmarkTests.length > 0)
              num = _controller.selectedAssessmentBenchmarkTests.length;
            //_assessmentBookType = _controller.currentAssessmentBookType.value;
            if (num != null && num > 0) {
              return GFBadge(
                child: Text('+$num'),
                size: 33,
              );
            } else {
              return Icon(
                Icons.assignment,
                color:
                    Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
                size: 27,
              );
            }
          }),
          elevation: 9,
          //splashColor: Colors.grey,
        ),
        // Container(
        //   width: 54.0,
        //   height: 54.0,
        //   decoration: BoxDecoration(
        //     shape: BoxShape.circle,
        //     color: Get.isDarkMode
        //         ? Colors.black.withOpacity(0.1)
        //         : AppTheme.colors.pinkBtn,
        //     boxShadow: [
        //       BoxShadow(
        //         color: Colors.red,
        //         offset: const Offset(
        //           1.0,
        //           1.0,
        //         ),
        //         blurRadius: 9.0,
        //         spreadRadius: 1.0,
        //       ), //BoxShadow
        //       BoxShadow(
        //         color: Colors.red.withOpacity(0.1),
        //         offset: const Offset(0.0, 0.0),
        //         blurRadius: 0.0,
        //         spreadRadius: 0.0,
        //       ),
        //     ],
        //   ),
        //   child: FloatingActionButton(
        //     backgroundColor: Get.isDarkMode
        //         ? Theme.of(context).primaryColorDark
        //         : AppTheme.colors.pinkBtn,
        //     foregroundColor: Get.isDarkMode
        //         ? Colors.black
        //         : Theme.of(context).primaryColorLight,
        //     heroTag: Text('createassessment0000'.tr),
        //     tooltip: 'Create Assessment'.tr,
        //     onPressed: () {
        //       //List<String> bookids = [];
        //       if (_controller.selectedAssessmentBenchmarkTests.length > 0) {
        //         // var type = Constants.assessmentTypes
        //         //     .where((element) =>
        //         //         element.assessmentType ==
        //         //         _assessmentBookType.assessmentType)
        //         //     .first
        //         //     .displayName;
        //
        //         Get.to(() => AssessmentSteps(
        //               isNew: true,
        //               books: _controller.selectedAssessmentBenchmarkTests,
        //             ));
        //
        //         // _controller.selectedAssessmentBooks.forEach(
        //         //   (element) {
        //         //     if (!bookids.contains(element.bookId))
        //         //       bookids.add(element.bookId.toString());
        //         //   },
        //         // );
        //         // var book = _controller.selectedAssessmentBooks[0];
        //         // var type = Constants.assessmentTypes
        //         //     .where((element) =>
        //         //         element.assessmentType ==
        //         //         _assessmentBookType.assessmentType)
        //         //     .first
        //         //     .displayName;
        //         // AssessedBooks books = new AssessedBooks();
        //         // books.assessedBooks = [];
        //         // books.assessedBooks?.add(AssessedBook(
        //         //     id: book.bookId, title: book.bookTitle, type: type));
        //
        //         // if (GetPlatform.isWeb || GetPlatform.isDesktop) {
        //         // } else {
        //         //   Get.to(() => InAppWebViewTeacherCreateAssessmentScreen(
        //         //         isNew: true,
        //         //         assessedBooks: books,
        //         //       ));
        //         // }
        //       } else {
        //         showGeneralDialog(
        //             context: context,
        //             transitionDuration: Duration(milliseconds: 400),
        //             pageBuilder: (bc, ania, anis) {
        //               return SimpleAlertDialog(
        //                   title: 'No Book'.tr,
        //                   message:
        //                       'Please select at least one book to ASSIGN!'.tr);
        //             });
        //       }
        //     },
        //     child: Obx(() {
        //       int? num;
        //       if (_controller.selectedAssessmentBenchmarkTests.length > 0)
        //         num = _controller.selectedAssessmentBenchmarkTests.length;
        //       //_assessmentBookType = _controller.currentAssessmentBookType.value;
        //       if (num != null && num > 0) {
        //         return GFBadge(
        //           child: Text('+$num'),
        //           size: 33,
        //         );
        //       } else {
        //         return Icon(
        //           Icons.assignment,
        //           color:
        //               Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
        //           size: 24,
        //         );
        //       }
        //     }),
        //     elevation: 5,
        //     //splashColor: Colors.grey,
        //   ),
        // ),
        SizedBox(height: 9),
        Visibility(
          visible: _userController.myClasses.isNotEmpty &&
              _userController.myClasses.length > 1,
          child: SizedBox(
            height: 45,
            width: 45,
            child: FloatingActionButton(
              backgroundColor: Get.isDarkMode
                  ? Theme.of(context).primaryColorDark
                  : AppTheme.colors.pinkBtn,
              foregroundColor:
                  Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
              tooltip: 'Switch Class'.tr,
              heroTag: 'switchclass8899',
              onPressed: () {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SwitchTeacherClassDialog();
                    });
              },
              child: Icon(
                Icons.class_outlined,
                color:
                    Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
                size: 24,
              ),
            ),
          ),
        ),
        // SizedBox(height: 5),
        // SizedBox(
        //   height: 45,
        //   width: 45,
        //   child: FloatingActionButton(
        //     heroTag: 'balbalhome8899',
        //     backgroundColor: Theme.of(context).primaryColorDark,
        //     foregroundColor: Get.isDarkMode
        //         ? Colors.black
        //         : Theme.of(context).primaryColorLight,
        //     tooltip: 'Home Page'.tr,
        //     onPressed: () {
        //       Get.delete<ReportsController>();
        //       Get.offAndToNamed('/teacher/home');
        //     },
        //     child: Icon(
        //       Icons.home_outlined,
        //       color:
        //           Get.isDarkMode ? Colors.black : Get.theme.primaryColorLight,
        //       size: 24,
        //     ),
        //   ),
        // ),
      ],
    );
  }
}
